package com.rc.saas.tenant.common.utils;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author: yang
 * @Date: 2022/6/9 10:17
 */
public class HandlerMethodUtil {

    //增删改
    public static String[] updateMothod = {"update", "edit", "renew"};
    public static String[] insertMothod = {"save", "insert", "add"};
    public static String[] delMothod = {"del", "remove"};

    public static Map<String, String> tableMap = new HashMap<>();

    static {
        tableMap.put("user", "用户");
        tableMap.put("carnumber", "车牌");
        tableMap.put("member", "会员");
        tableMap.put("pile", "充电桩");
        tableMap.put("gun", "充电枪");
        tableMap.put("station", "站点");
        tableMap.put("operator", "加盟商");
        tableMap.put("enterprise", "企业");
        tableMap.put("channel", "渠道商");
        tableMap.put("agreement", "协议");
        tableMap.put("lable", "标签");
        tableMap.put("msg", "消息");
        tableMap.put("setting", "设置");
        tableMap.put("evaluate", "评论");
        tableMap.put("ticket", "优惠券");
        tableMap.put("market", "活动");
        tableMap.put("order", "订单");
        tableMap.put("discount", "折扣优惠");
        tableMap.put("guide", "指南");
        tableMap.put("notice", "公告");
        tableMap.put("welcome", "欢迎页");
        tableMap.put("receiver", "欢迎页");
        tableMap.put("index", "欢迎页");
        tableMap.put("trece", "日志");

    }

    public static String getActionType(String handlerMethodName) {
        for (String s : updateMothod) {
            if (handlerMethodName.contains(s)) {
                return "修改";
            }
        }

        for (String s : insertMothod) {
            if (handlerMethodName.contains(s)) {
                return "新增";
            }
        }
        for (String s : delMothod) {
            if (handlerMethodName.contains(s)) {
                return "删除";
            }
        }

        return "查询";
    }

    /**
     * @param handlerMethodName
     * @param type              0操作表 1操作模块
     * @return
     */
    public static String getTableName(String handlerMethodName, int type) {
        String s1 = handlerMethodName.toLowerCase();
        for (String s : tableMap.keySet()) {
            if (s1.contains(s)) {
                if (type == 0) {
                    return tableMap.get(s) + "表";
                } else {
                    return tableMap.get(s) + "模块";
                }
            }
        }


        if (type == 0) {
            return "其他" + "表" + s1;
        } else {
            return "其他" + "模块" + s1;
        }
    }


}
